package goleetcode

func minimumSeconds(nums []int) int {
	hash := make(map[int][]int)
	n := len(nums)
	res := n
	for i, num := range nums {
		hash[num] = append(hash[num], i)
	}
	for _, pos := range hash {
		mx := pos[0] + n - pos[len(pos) - 1]
		for i := 1; i < len(pos); i++ {
			mx = max(mx, pos[i] - pos[i - 1])
		}
		res = min(res, mx / 2)
	}
	return res
}